import express from "express";
import allDataSearch from "../common/allDataSearch.js";
import paramsSearch from "./paramsSearch.js";

const consumptionRecords = express.Router();

consumptionRecords.post("/consumptionRecords", async (req, res) => {
    try {
        const params = req.body;
        const dataRes:any =Object.keys(params).length === 0 ? await allDataSearch('consumptionRecord') : await paramsSearch(params); // Wait for the query to complete
        res.send({
            code: 200,
            message: "消费记录接口 请求成功！",
            result: dataRes,
            total: dataRes.length,
        });
    } catch (error) {
        console.error('Error fetching file records:', error);
        res.status(500).send({
            code: 1,
            message: "消费记录接口 请求失败！",
            result: null,
        });
    }
});

export default consumptionRecords;